﻿<%@ Page Title="POSSystem | Stock Take" Language="C#" MasterPageFile="~/Application.Master" AutoEventWireup="true"
    CodeBehind="StockTake.aspx.cs" Theme="POSSystem" Inherits="WebUI.StockTake" %>

<%@ Register Src="~/Controls/SysControls/PageHeader.ascx" TagPrefix="uc" TagName="PageHeader" %>
<%@ Register Src="~/Controls/POSControls/ProductListCtrl.ascx" TagName="ProductList"
    TagPrefix="uc" %>
<%@ Register Src="~/Controls/SysControls/GridFilterPaging.ascx" TagName="GridFilterPaging"
    TagPrefix="uc" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ApplicationHeadHolder" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ApplicationContentHolder" runat="server">

    <script type="text/javascript">
        function btnLocation_click(btn) {
            var hidSelectedLocation = document.getElementById("<%=hidSelectedLocation.ClientID%>");
            hidSelectedLocation.value = btn.getAttribute("LocationID");

            var btnLoadByLocation = document.getElementById("<%=btnLoadByLocation.ClientID%>");
            if (btnLoadByLocation != null)
                btnLoadByLocation.click();
        }

        function onAddLocation() {
            var returnValue = window.showModalDialog('<%=GetLocationEditPageLink() %>' + '&mode=new', '', 'dialogWidth=500px;dialogHeight=200px;resizable=no;help=no;unadorned=yes;');

            return returnValue > 0;
        }

        function onEditLocation(btn) {
            var hidSelectedLocation = document.getElementById("<%=hidSelectedLocation.ClientID%>");
            if (hidSelectedLocation.value == '' || hidSelectedLocation.value == undefined) {
                alert('Please select a Location!');
                return false;
            }

            var returnValue = window.showModalDialog('<%=GetLocationEditPageLink() %>' + '&mode=edit&id=' + hidSelectedLocation.value,
                '', 'dialogWidth=500px;dialogHeight=200px;resizable=no;help=no;unadorned=yes;');

            return returnValue > 0;
        }

        function onRemoveLocation() {
            var hidSelectedLocation = document.getElementById("<%=hidSelectedLocation.ClientID%>");

            if (hidSelectedLocation.value == '' || hidSelectedLocation.value == undefined || hidSelectedLocation.value == '-999') {
                alert('Please select a Location!');
                return false;
            }
            return confirm("Do you want to delete the selected location?");
        }

        function showPrintDlg(key) {
            var returnValue = window.showModalDialog(key, '', 'dialogWidth=800px;dialogHeight=600px;resizable=yes;help=no;unadorned=yes;');
        }

        function onViewDetails() {
            var hidSelectedItemID = document.getElementById("<%=hidSelectedItemID.ClientID%>");
            var id  = getSelectedItemID<%=lstProducts.ClientID %>();

            if(id == null){
                alert("No item was selected!");
                return false;
            }
            
            hidSelectedItemID.value = id;
            return true;
        }
    </script>
    <uc:PageHeader ID="pageHeader" Text="Stock Take" ImageURL="~/Images/Inventory.png"
        runat="server" />
    <table width="100%">
        <tr>
            <td style="width: 250px; text-align: left; vertical-align: top">
                <asp:UpdatePanel ID="updateLocation" runat="server">
                    <ContentTemplate>
                        <asp:Panel ID="panelStockLocation" runat="server" class="primaryPanel">
                            <div class="titleBar">
                                <asp:Label ID="lblTitle1" runat="server" CssClass="titleContent">Stock Location</asp:Label>
                            </div>
                            <div class="primaryFrameNoBorder">
                                <div>
                                    <table class="toolbar" width="100%">
                                        <tr>
                                            <td>
                                                <asp:LinkButton class="tbbutton" ID="btnAddLocation" runat="server" OnClientClick="return onAddLocation();"
                                                    OnClick="btnAddLocation_OnClick">
                                                    <img src="Images/AddRecord.gif" /><asp:Label ID="label1" runat="server" Text="Add"></asp:Label>
                                                </asp:LinkButton>
                                                <asp:LinkButton class="tbbutton" ID="btnEditLocation" runat="server" OnClientClick=" return onEditLocation();"
                                                    OnClick="btnAddLocation_OnClick">
                                                    <img src="Images/Edit.gif" /><asp:Label ID="label2" runat="server" Text="Edit"></asp:Label>
                                                </asp:LinkButton>
                                                <asp:LinkButton class="tbbutton" ID="btnRemoveLocation" runat="server" OnClientClick="return onRemoveLocation();"
                                                    OnClick="btnRemoveLocation_OnClick">
                                                    <img src="Images/Delete.gif" /><asp:Label ID="label3" runat="server" Text="Delete"></asp:Label>
                                                </asp:LinkButton>
                                            </td>
                                        </tr>
                                    </table>
                                </div>
                                <div id="litLocations" runat="server">
                                </div>
                                <div style="display: none">
                                    <asp:HiddenField ID="hidSelectedLocation" runat="server" />
                                </div>
                                <div>
                        </asp:Panel>
                    </ContentTemplate>
                </asp:UpdatePanel>
            </td>
            <td style="text-align: right; vertical-align: top">
                <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                     <Triggers>
                        <asp:PostBackTrigger ControlID="btnExcel" />
                    </Triggers>
                    <ContentTemplate>
                        <asp:Panel ID="panelDetails" runat="server" class="primaryPanel" DefaultButton="btnSearchProduct" >
                            <div class="titleBar">
                                <asp:Label ID="Label4" runat="server" CssClass="titleContent">Product Details</asp:Label>
                            </div>
                            <div class="primaryFrameNoBorder">
                                <div>
                                    <table width="100%" class="toolbar">
                                        <tr>
                                            <td style='vertical-align: middle'>
                                                <asp:LinkButton class="tbbutton" ID="btnAddProd" runat="server" OnClientClick="return onViewDetails();"
                                                    OnClick="btnViewDetail_OnClick">
                                                    <img src="Images/icon_details.gif" /><asp:Label ID="label5" runat="server" Text="View Details"></asp:Label>
                                                </asp:LinkButton>
                                                <img src="Images/tbSep.png" />
                                                <asp:LinkButton class="tbbutton" ID="btnPrintProduct" runat="server" OnClick="btnPrintProduct_OnClick">
                                                    <img src="Images/print.gif" /><asp:Label ID="label8" runat="server" Text="Print"></asp:Label>
                                                </asp:LinkButton>
                                                <asp:LinkButton class="tbbutton" ID="btnExcel" runat="server" OnClick="btnExcel_OnClick">
                                                    <img src="Images/excel.gif" /><asp:Label ID="label9" runat="server" Text="Export"></asp:Label>
                                                </asp:LinkButton>
                                                <img src="Images/tbSep.png" />
                                                <asp:TextBox ID="txtSearchProduct" runat="server"></asp:TextBox>
                                                <asp:LinkButton class="tbbutton" ID="btnSearchProduct" runat="server" OnClick="btnSearchProduct_OnClick">
                                    <img src="Images/search.png" />
                                                </asp:LinkButton>
                                                <img src="Images/tbSep.png" />
                                                <asp:LinkButton class="tbbutton" ID="btnReload" runat="server" OnClick="btnReload_OnClick">
                                                    <img src="Images/reload.png" /><asp:Label ID="label11" runat="server" Text="Reload"></asp:Label>
                                                </asp:LinkButton>
                                            </td>
                                            <td style='vertical-align: middle; text-align: right'>
                                                <asp:Label ID="label10" runat="server" Text="Brand:"></asp:Label>
                                                <asp:DropDownList ID="ddlBrand" runat="server" class='searchTextBox' AutoPostBack="true"
                                                    OnSelectedIndexChanged="ddlBrand_OnSelectedIndexChanged">
                                                </asp:DropDownList>
                                            </td>
                                        </tr>
                                    </table>
                                </div>
                                <uc:ProductList ID="lstProducts" runat="server" Width="100%" AllowPaging="true" AllowSorting="true"
                                    AllowSelecting="true" SaveOnCommit="false" />
                                <div style="height: 10px">
                                    &nbsp;</div>
                                <uc:GridFilterPaging ID="gridFilterPaging" runat="server" FilteredField="ProductName"
                                    OnNeedListControl="gridFilterPaging_OnNeedListControl" />
                                <asp:Button ID="btnLoadByLocation" runat="server" OnClick="btnLoadByLocation_OnClick"
                                    Style="display: none" />
                                <asp:HiddenField ID="hidSelectedItemID" runat="server" />
                            </div>
                        </asp:Panel>
                    </ContentTemplate>
                </asp:UpdatePanel>
            </td>
        </tr>
    </table>
</asp:Content>
